package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.system.domain.CardMemberInfo;
import com.ruoyi.system.service.ICardMemberInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CardEmptycardMapper;
import com.ruoyi.system.domain.CardEmptycard;
import com.ruoyi.system.service.ICardEmptycardService;

/**
 * 空卡制作Service业务层处理
 *
 * @author ruoyi
 * @date 2025-01-25
 */
@Service
public class CardEmptycardServiceImpl implements ICardEmptycardService
{
    @Autowired
    private CardEmptycardMapper cardEmptycardMapper;
    @Autowired
    private ICardMemberInfoService cardMemberInfoService;

    /**
     * 查询空卡制作
     *
     * @param inputId 空卡制作主键
     * @return 空卡制作
     */
    @Override
    public CardEmptycard selectCardEmptycardByInputId(Long inputId)
    {
        return cardEmptycardMapper.selectCardEmptycardByInputId(inputId);
    }

    /**
     * 查询空卡制作列表
     *
     * @param cardEmptycard 空卡制作
     * @return 空卡制作
     */
    @Override
    public List<CardEmptycard> selectCardEmptycardList(CardEmptycard cardEmptycard)
    {
        return cardEmptycardMapper.selectCardEmptycardList(cardEmptycard);
    }

    /**
     * 新增空卡制作
     *
     * @param cardEmptycard 空卡制作
     * @return 结果
     */
    @Override
    public int insertCardEmptycard(CardEmptycard cardEmptycard)
    {
        cardEmptycard.setCreateTime(DateUtils.getNowDate());
        cardEmptycard.setLsh(IdUtils.fastSimpleUUID());
        cardEmptycardMapper.insertCardEmptycard(cardEmptycard);
        return cardMemberInfoService.insertCardMemberInfoBatch(cardEmptycard);
    }

    /**
     * 修改空卡制作
     *
     * @param cardEmptycard 空卡制作
     * @return 结果
     */
    @Override
    public int updateCardEmptycard(CardEmptycard cardEmptycard)
    {
        cardEmptycard.setUpdateTime(DateUtils.getNowDate());
        cardEmptycardMapper.updateCardEmptycard(cardEmptycard);
        return cardMemberInfoService.updateCardMemberInfoBatch(cardEmptycard);
    }

    /**
     * 批量删除空卡制作
     *
     * @param inputIds 需要删除的空卡制作主键
     * @return 结果
     */
    @Override
    public int deleteCardEmptycardByInputIds(Long[] inputIds)
    {
        List<CardEmptycard> cardEmptycards = new ArrayList<>();
        for (int i = 0; i < inputIds.length; i++) {
            CardEmptycard cardEmptycard = cardEmptycardMapper.selectCardEmptycardByInputId(inputIds[i]);
            cardEmptycards.add(cardEmptycard);
        }
        // cardEmptycardMapper.deleteCardEmptycardByInputIds(inputIds);
        cardEmptycardMapper.updateCardEmptycardByInputIds(inputIds);
        return cardMemberInfoService.deleteCardMemberInfoBatch(cardEmptycards);
    }

    /**
     * 删除空卡制作信息
     *
     * @param inputId 空卡制作主键
     * @return 结果
     */
    @Override
    public int deleteCardEmptycardByInputId(Long inputId)
    {
        List<CardEmptycard> cardEmptycards = new ArrayList<>();
        CardEmptycard cardEmptycard = cardEmptycardMapper.selectCardEmptycardByInputId(inputId);
        cardEmptycards.add(cardEmptycard);
        cardEmptycardMapper.deleteCardEmptycardByInputId(inputId);
        return cardMemberInfoService.deleteCardMemberInfoBatch(cardEmptycards);
    }
}
